package aquarium.time;

import java.util.ArrayList;
import java.util.Collection;

import aquarium.gui.Aquarium;
import aquarium.items.AquariumItem;


public class TManager {
	
	private ArrayList<Timer> _list;
	private Collection<AquariumItem> _items;
	private Aquarium _aquarium;
	
	public TManager(Collection<AquariumItem> items, Aquarium aquarium) {
		this._list = new ArrayList<Timer>();
		this._items = items;
		this._aquarium = aquarium;
	}
	
	public void startAll() {
		for(Timer t : _list) {
			t.start();
		}
	}

	public Timer getTimer(TimerKind kind, long wait_time) {
		for(int i=0; i<_list.size(); i++) {
			if (_list.get(i).equals(kind, wait_time)) {
				return _list.get(i);
			}
		}
		return null;
	}

	public void addObserver(AquariumItem item, TimerKind kind, long moveDelay) {
		for(int i=0; i<_list.size(); i++) {
			if (_list.get(i).equals(kind, moveDelay)) {
				_list.get(i).addObserver(item);
				return;
			}
		}
		Timer t = new Timer(_items, kind, moveDelay, _aquarium);
		t.addObserver(item);
		_list.add(t);
	}

}
